#include "base64.h"
#include <memory>
#include <stdio.h>


bool createPicFromBase64Buf(const char * src, std::string desPath)
{
    bool ret = true;

    /* 计算结果长度并申请内存 */
    int dstLen = Base64decode_len(src);
    std::unique_ptr<char[]> pDst(new char[dstLen + 1]);
    pDst[dstLen] = 0;

    /* 解码 */
    Base64decode(pDst.get(), src);
    
    /* 打开文件 */
    FILE * fp = fopen(desPath.c_str(), "w");
    ret = ret && (nullptr != fp);
    if(!ret)
    {
        printf("Fail to open file:%s\n", desPath.c_str());
        return ret;
    }

    int writeRet = fwrite(pDst.get(), 1, dstLen, fp);
    ret = ret && (writeRet == dstLen);
    if(!ret)
    {
        printf("Fail to write file:%s, writeRet=%d, dstLen=%d\n", desPath.c_str(),
            writeRet, dstLen);
        fclose(fp);
        return ret;
    }

    fclose(fp);
    return ret;
}

int main(int argc, const char *argv[])
{
    const char *p = "/9j/4AAQSkZJRgABAQEAYABgAAD/4QBwRXhpZgAATU0AKgAAAAgABgESAAMAAAABAAEAAAExAAIAAAARAAAAVgMgAAIAAAAEVHV4AFEQAAEAAAABAQAAAFERAAQAAAABAAAEGlESAAQAAAABAAAEGgAAAAB3d3cuaW5rc2NhcGUub3JnAAD/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/wAARCACFAHwDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp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